package com.atguigu.lease.web.admin.controller.apartment;

import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.entity.FacilityInfo;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.admin.service.FacilityInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by 小可乐$ on 2024/8/12$ 19:41$
 * description:配套信息管理
 */
@Tag(name = "配套信息管理")
@RestController
@RequestMapping("/admin/facility")
public class FacilityController {
    @Autowired
    private FacilityInfoService service;

    /**
     * 新增或修改配套信息
     * */
    @PostMapping("saveOrUpdate")
    @Operation(summary = "新增或修改配套信息")
    public Result saveOrUpdate(
            @RequestBody FacilityInfo facilityInfo){
        service.saveOrUpdate(facilityInfo);
        return Result.ok();
    }
    /**
     * [根据类型查询配套信息列表]
     * */
    @GetMapping("list")
    @Operation(summary = "[根据类型]查询配套信息列表")
    public Result<List<FacilityInfo>> findAll(
            @RequestParam(required = false) ItemType type){
        LambdaQueryWrapper<FacilityInfo> facilityInfoLambdaQuery = new LambdaQueryWrapper<>();
        facilityInfoLambdaQuery.eq(type!=null,FacilityInfo::getType,type);
        List<FacilityInfo> list = service.list(facilityInfoLambdaQuery);
        return Result.ok(list);
    }
    /**
     * 根据id删除配套信息
     * */
    @DeleteMapping("/deleteById")
    @Operation(summary = "根据id删除配套信息")
    public Result deleteById(@RequestParam Long id){
        service.removeById(id);
        return Result.ok();
    }
}
